package com.cqc.googleplay.activity;

import com.cqc.googleplay.R;
import com.cqc.googleplay.http.HttpHelper;
import com.cqc.googleplay.http.NetUrl;
import com.cqc.googleplay.view.ContentPager;

import android.content.Context;
import android.os.Bundle;
import android.support.v7.app.ActionBar;
import android.support.v7.app.ActionBarActivity;
import android.view.MenuItem;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.ScrollView;

public class AppDetailActivity extends ActionBarActivity {
	
	private ContentPager contentPager;
	private Context context;
	private View rootView;
	private ScrollView scrollvi1ew;
	private LinearLayout layout_parts;
	private LinearLayout layout_bottom;
	private String packageName;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		context = this;
		contentPager = new ContentPager(this) {
			
			@Override
			public Object requestData() {
				return getData();
			}
			
			@Override
			public View createSuccessView() {
				return getSuccessView();
			}
		};
		setContentView(contentPager);
		initActionBar();		
	}

	protected Object getData() {
		packageName = getIntent().getStringExtra("packageName");
		String json = HttpHelper.get(NetUrl.DETAIL+packageName);
		return json;
	}

	protected View getSuccessView() {
		rootView = View.inflate(context, R.layout.activity_detail, null);
		scrollvi1ew = (ScrollView) rootView.findViewById(R.id.scrollview);
		layout_parts = (LinearLayout) rootView.findViewById(R.id.layout_parts);
		layout_bottom = (LinearLayout) rootView.findViewById(R.id.layout_bottom);
		return rootView;
	}

	private void initActionBar() {
		ActionBar actionBar = getSupportActionBar();
		actionBar.setDisplayShowHomeEnabled(true);
		actionBar.setDisplayHomeAsUpEnabled(true);
		actionBar.setTitle("应用详情");	
	}
	
	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		//点击导航栏，让其消失
		if (item.getItemId() == android.R.id.home) {
			finish();
		}
		return super.onOptionsItemSelected(item);
	}
}
